package org.linlinjava.litemall.db.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.linlinjava.litemall.db.dao.AdminMapper;
import org.linlinjava.litemall.db.models.Admin;
import org.linlinjava.litemall.db.service.AdminService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin>
        implements AdminService {

    @Override
    public List<Admin> findAdmin(String username) {
        QueryWrapper<Admin> query = new QueryWrapper<>();
        query.eq("username", username);
        return this.baseMapper.selectList(query);
    }

    @Override
    public IPage<Admin> querySelective(String username, Integer pageNo, Integer pageSize) {
        Page<Admin> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Admin> query = new QueryWrapper<>();
        query.like(!StringUtils.isEmpty(username),"username", username);
        return this.baseMapper.selectPage(page, query);
    }

    @Override
    public List<Admin> all() {
        QueryWrapper<Admin> query = new QueryWrapper<>();
        return baseMapper.selectList(query);
    }
}
